<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\model\Gcategory;
use app\admin\model\Goods;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Good extends BaseController
{
    public function good_list()
    {

        $recommended=Request::get('recommended',"" ,'trim,htmlspecialchars,strip_tags');
        $if_show=Request::get('if_show',"" ,'trim,htmlspecialchars,strip_tags');
        $if_open=Request::get('if_open',"" ,'trim,htmlspecialchars,strip_tags');
        $keywords=Request::get('keywords',"" ,'trim,htmlspecialchars,strip_tags');
        $maxtime = Request::get('maxtime','','trim,htmlspecialchars,strip_tags');
        $mintime = Request::get('mintime','','trim,htmlspecialchars,strip_tags');
        $cid = Request::get('cid','','trim,htmlspecialchars,strip_tags');
        $maxqian = Request::get('maxqian','','trim,htmlspecialchars,strip_tags');
        $minqian = Request::get('minqian','','trim,htmlspecialchars,strip_tags');

        $data = [
            'recommended'=>$recommended,
            'if_show'=>$if_show,
            'if_open'=>$if_open,
            'keywords'=>$keywords,
            'maxtime'=>$maxtime,
            'mintime'=>$mintime,
            'cate_id'=>$cid,
            'maxqian'=>$maxqian,
            'minqian'=>$minqian,

        ];
          $rt = Goods::golist($data,input('get.'));
//        $list = Db::table('ecm_goods')->field("ecm_goods.*,ecm_brand.brand_name,ecm_gcategory.cate_name")
//                ->join("ecm_brand",'ecm_goods.brand=ecm_brand.brand_id',"LEFT")
//                ->join("ecm_gcategory","ecm_goods.cate_id=ecm_gcategory.cate_id","LEFT");
      /*  if($recommended!=""){
            $list->where('ecm_goods.recommended',$recommended);
        }*/


//        if($if_show!=""){
//            $list->where('ecm_goods.if_show',$if_show);
//        }
//        if($if_open!=""){
//            $list->where('ecm_goods.if_open',$if_open);
//        }
//        if($keywords!=""){
//            $list->whereLike('goods_name',"%{$keywords}%");
//
//        }

//        if($maxtime!="" and $mintime!=""){
//            $list->whereBetweenTime('add_time',$maxtime,$mintime);
//        }elseif($maxtime=="" and $mintime!=""){
//            $list->whereTime('add_time','<=',$mintime);
//        }elseif ($maxtime!="" and $mintime==""){
//            $list->whereTime('add_time','>=',$maxtime);
//        }

//        if($maxqian!="" and $minqian!=""){
//            $list->whereBetween('price',"$maxqian,$minqian");
//        }elseif ($maxqian=="" and $minqian!=""){
//            $list->where('price','<=',"$minqian");
//        }elseif ($maxqian!="" and $minqian==""){
//            $list->where('price','>=',"$maxqian");
//        }
//        if ($cid!=""){
//            $list->where('ecm_goods.cate_id',$cid);
//        }
//        $rt = $list->paginate([
//            'list_rows'=>10,
//            'query'=>Request::get()
//        ])->each(function ($v,$k){
//            $v['goods_name'] = str_replace(Request::get('keywords'),"<span style='color: red;font-weight: bolder;'>".Request::get('keywords')."</span>",$v['goods_name']);
//            return $v;
//        });
//        foreach ($rt as $k=>$v){
//            $rt[$k]['goods_name'] = str_replace($keywords,"<span style='color: red;font-weight: bolder;'>$keywords</span>",$rt[$k]['goods_name']);
//        }
//        $page = $rt->render();
//        View::assign('page',$page);
//
            View::assign('rt',$rt);
        $rt1=Gcategory::fen()->toArray();
        View::assign('rt1',$rt1);
        View::assign($data);

//        View::assign('keywords',$keywords);
//        View::assign('if_show',$if_show);
//        View::assign('recommended',$recommended);
//        View::assign('if_open',$if_open);
//        View::assign('maxtime',$maxtime);
//        View::assign('mintime',$mintime);
//        View::assign('maxqian',$maxqian);
//        View::assign('minqian',$minqian);
//        View::assign('cate_id',$cid);

        return View::fetch();
    }
}